package com.opentracing;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.log.Fields;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;

import java.util.List;
import java.util.Map;

public class MockTest {
    public static void main(String[] args) {
        // Initialize MockTracer with the default values.
        MockTracer tracer = new MockTracer();
        MockSpan span = tracer.buildSpan("root").start();
        try (Scope scope = tracer.scopeManager().activate(span)) {
            // Do things.
            span.setTag(Tags.COMPONENT, "my-own-application");
            System.out.println("current: "+tracer.scopeManager().activeSpan().toString());

            // 第二个

            MockSpan subspan = tracer.buildSpan("sub").start();
            try (Scope subscope = tracer.scopeManager().activate(subspan)) {
                subspan.setTag(Tags.COMPONENT, "my-own-application2");
                System.out.println("current: "+tracer.scopeManager().activeSpan().toString());
                subspan.finish();
            }


        } catch(Exception ex) {
            Tags.ERROR.set(span, true);
            span.log(System.currentTimeMillis(),"errormsg");
        } finally {
            span.finish();
        }

        List<MockSpan> spans = tracer.finishedSpans();
        for(MockSpan espan:spans){
            System.out.println(espan.toString());
        }


    }
}
